<?php

class   Common_DataTable_Summary_Calculated 
extends Common_DataTable_Summary_Abstract 
{

    private $arr_applicable_columns   = array();
    
    private $arr_values_static        = array();
    private $arr_values_static_group  = array();
    
    public function __construct() {
        parent::__construct();
    }

    public function initialise($arr_columns, $arr_groups = null) {

        $this->arr_applicable_columns = array();
        
        // todo: make number constant
        foreach($arr_columns as $str_column_key => $arr_column) {
            if(isset($arr_column['type']) && ($arr_column['type'] == 'number')) {
                $this->arr_applicable_columns[] = $str_column_key;
            }
        }
        
    }
    
    protected function getApplicableColumnKeys() {
        return $this->arr_applicable_columns;
    }
    
    public function setStaticValues($arr) {
        if(is_array($arr)) {
            $this->arr_values_static = $arr;
        }
    }
    
    public function getStaticValues() {
        return $this->arr_values_static;
    }
    
    public function setStaticValuesForGroup($arr) {
        if(is_array($arr)) {
            $this->arr_values_static_group = $arr;
        }
    }
    
    public function getStaticValuesForGroup() {
        return $this->arr_values_static_group;
    }
    
    public function getData($int_data_count = null) {
        $arr_merged = array_merge($this->_getData(), $this->getStaticValues());
        
        $arr_merged = $this->applyVariables($arr_merged, array(
            '__COUNT__' => $int_data_count
        ));
        
        return $arr_merged;
    }
    
    protected function _getData() {
        return array();
    }
    
    public function getDataForGroup($str_group_key, $str_group_label = null, $int_group_count = null) {
        $arr_merged = array_merge($this->_getDataForGroup($str_group_key), $this->getStaticValuesForGroup());
        
        $arr_merged = $this->applyVariables($arr_merged, array(
            '__GROUP__' => $str_group_label, 
            '__COUNT__' => $int_group_count
        ));
        
        return $arr_merged;
    }
    
    protected function _getDataForGroup($str_group_key) {
        return $this->arr_group_sums[$str_group_key];
    }

}
